package com.wk.job;

import java.io.Serializable;
import java.util.Date;

/***
 * 计算节点执行的任务信息 一个Job代表着一个省份的计算任务。 该任务由一个Task生成。因为一个Task可能生成多个Job
 * 
 * @author wkhuahuo
 *
 */
public class Job implements Serializable {
	/**
	 * 序列化之后传输给客户端
	 */
	private static final long serialVersionUID = 1L;
	private final double FINISH = 1;
	private String jobName;// 任务名字[rfe_ay_st]
	private String jobProper;// 任务省份 53,531101
	private double jobInfo;// 任务百分比
	private String jobAddress;// job分发计算地址
	private String jobDistributeTime;// 任务分发给计算节点的时间
	private String jobBeginTime;// 任务开始时间
	private String jobEndTime = "NULL";// 任务结束时间没有结束默认为NULL
	private int taskId = -1;
	private boolean isFinished = false;// true：当所有子任务都成功
	private boolean isFailed = false;// true：当任一子任务失败

	public Job(String jobName, String jobProper) {
		this.jobName = jobName;
		this.jobProper = jobProper;
	}

	public Job(String jobName, String jobProper, double jobInfo, String jobDistributeTime) {
		this.jobName = jobName;
		this.jobProper = jobProper;
		this.jobInfo = jobInfo;
		this.jobDistributeTime = jobDistributeTime;
	}

	public String getJobName() {
		return jobName;
	}

	public void setJobName(String jobName) {
		this.jobName = jobName;
	}

	public String getJobProper() {
		return jobProper;
	}

	public void setJobProper(String jobProper) {
		this.jobProper = jobProper;
	}

	public double getJobInfo() {
		return jobInfo;
	}

	public void setJobInfo(double jobInfo) {
		if (jobInfo - 1.0 < 0.000001) {
			jobEndTime = String.valueOf(new Date().getTime());
		}
		this.jobInfo = jobInfo;
	}

	public String getJobDistributeTime() {
		return jobDistributeTime;
	}

	public void setJobDistributeTime(String jobDistributeTime) {
		this.jobDistributeTime = jobDistributeTime;
	}

	public String getJobBeginTime() {
		return jobBeginTime;
	}

	public void setJobBeginTime(String jobBeginTime) {
		this.jobBeginTime = jobBeginTime;
	}

	public String getJobEndTime() {
		return jobEndTime;
	}

	public void setJobEndTime(String jobEndTime) {
		this.jobEndTime = jobEndTime;
	}

	/* 返回该job的唯一标识 */
	public String getId() {
		return jobDistributeTime + jobProper;
	}

	public int getTaskId() {
		return taskId;
	}

	public void setTaskId(int taskId) {
		this.taskId = taskId;
	}

	public boolean isFinished() {
		isFinished = jobInfo >= FINISH ? true : false;
		return isFinished;
	}

	public String getJobAddress() {
		return jobAddress;
	}

	public void setJobAddress(String jobAddress) {
		this.jobAddress = jobAddress;
	}

	public void setFailed() {
		isFailed = true;
	}

	public boolean isFailed() {
		return isFailed;
	}

	@Override
	public String toString() {
		return "Job [FINISH=" + FINISH + ", jobName=" + jobName + ", jobProper=" + jobProper + ", jobInfo=" + jobInfo
				+ ", jobAddress=" + jobAddress + ", jobDistributeTime=" + jobDistributeTime + ", jobBeginTime="
				+ jobBeginTime + ", jobEndTime=" + jobEndTime + ", taskId=" + taskId + ", isFinished=" + isFinished
				+ ", isFailed=" + isFailed + "]";
	}

}
